import React, { PureComponent } from 'react';
import {
    Row,
    Col,
    Card,
    Form,
    Button,
    Input,
    DatePicker,
    Table,
    Select,
    Icon,
    Divider,
    Popconfirm,
    Modal,
    message,
    Alert,
    Steps
} from 'antd';
import moment from 'moment';
import { connect } from 'dva';
import router from 'umi/router';
import Editor from '../Emergency/Editor'
const FormItem = Form.Item;
const Option = Select.Option;
@Form.create()
@connect(({ ProjectContact }) => ({

    record: ProjectContact.record,

}))
class ProjectContactEdit extends PureComponent {
    constructor(props) {
        super(props);
        this.state = {
            visible: false,
        };
        this.dispatch = this.props.dispatch;
    }
    submitAddValues = (values) => {

        values.lxnr =  this["editor"].state.text;

        const hide = message.loading('正在编辑...', 0);
        this.props.dispatch({
            type: 'ProjectContact/fetchProjectContactEdit',
            payload: {
                cm: values,
            },
            callback: response => {
                hide();
                if (response.status) {
                    message.success('编辑成功');
                    this.setState({ visible: false });
                    this.props.fetchList();
                } else {
                    message.error(response.ErrorMessage);
                    console.log(response.ErrorMessage);
                }
            },
        });
    }
    submmitFormValues = () => {
        this.props.form.validateFields((err, values) => {
            if (!err) {
               
                 this.submitAddValues(values);
            }
        })
    }
    setFormValues = ({ values = null } = {}) => {

        this.props.form.setFieldsValue(values);

    }
    OnRef=({ref=null,type=null}={})=>{
        this[type] = ref;
    }
    componentDidMount() {
        // debugger
        this.props.OnRef({ ref: this, type: 'EditForm' });
        
    }
    render() {
        const { getFieldDecorator } = this.props.form;
        const { record } = this.props;

        const formItemLayout = {
            labelCol: {
                xs: { span: 24 },
                sm: { span: 24 },
            },
            wrapperCol: {
                xs: { span: 24 },
                sm: { span: 24 },
            },
        };
        const width = '200px';
        // console.log(record)
        return (
            <><Modal
                title="新增或编辑"
                width={'70%'}
                style={{ top: 20 }}
                destroyOnClose
                visible={this.state.visible}
                onOk={() => {
                    this.submmitFormValues();
                }}
                onCancel={() => {
                    this.setState({ visible: false });
                }}

            >
                <Card style={{ margin: '5px 0' }}>
                    <Form labelAlign="left" layout={'inline'} {...formItemLayout} >
                        <Row>
                            <Col span={8} >
                                <FormItem label="工程名称" >
                                    {getFieldDecorator('gcmc', {
                                        initialValue: record&&record.gcmc, rules: [
                                            {
                                                required: true,
                                                message: '工程名称',
                                            },
                                        ],
                                    })(<Input placeholder="工程名称" style={{ width: width }} />)}
                                </FormItem>
                            </Col>
                           
                        </Row>
                        <Row>
                            <Col span={8}>
                                <FormItem label="抄送单位名称1" >
                                    {getFieldDecorator('csdwmc', {
                                        initialValue: record&&record.csdwmc,
                                    })(<Input placeholder="抄送单位名称1" style={{ width: width }} />)}
                                </FormItem></Col>


                            <Col span={8}>
                                <FormItem label="抄送单位名称2" >
                                    {getFieldDecorator('csdwmc2', {
                                        initialValue: record&&record.csdwmc2,
                                    })(<Input placeholder="抄送单位名称2" style={{ width: width }}  />)}
                                </FormItem>
                            </Col>
                            <Col span={8}>
                                <FormItem label="联系提要" >
                                    {getFieldDecorator('lxty', {
                                        initialValue: record&&record.lxty,
                                    })(<Input placeholder="联系提要" style={{ width: width }} />)}
                                </FormItem>
                            </Col>
                        </Row>
                        <Row>
                            <Col span={8}>
                            <FormItem label="联系提要" style={{display:'none'}}>
                                    {getFieldDecorator('id', {
                                        initialValue: record&&record.id,
                                    })(<Input placeholder="联系提要" style={{ width: width }} />)}
                                </FormItem>
                            </Col>

                        </Row>
                    </Form>
                    <br/>
                    <Row>
                        <Col span={24}>
                            <span style={{color: 'rgba(0, 0, 0, 0.85)','fontSize': '14px'}}>联系内容：</span>
                        </Col>

                    </Row>
                    <br/>
                    <Row>
                        <Col span={24}>
                            <Editor OnRef={this.OnRef} record={record}/>
                        </Col>

                    </Row>

                </Card>
            </Modal></>
        )
    }
}



export default ProjectContactEdit;